package com.deschen.security.core.social;

import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
import org.springframework.social.security.SocialAuthenticationFilter;
import org.springframework.social.security.SpringSocialConfigurer;

/**
 * @Author deschen
 * @Create 2019/9/4
 * @Description 继承配置social的过滤器配置类
 * @Since 1.0.0
 */
public class CustomSpringSocialConfigurer extends SpringSocialConfigurer {

    // 通过配置文件配置路径
    // 认证链接
    private String filterProcessesUrl;
    // 注册链接
    private String signupUrl;

    public CustomSpringSocialConfigurer(
            String filterProcessesUrl, String signupUrl) {
        this.filterProcessesUrl = filterProcessesUrl;
        this.signupUrl = signupUrl;
    }

    /**
     * SocialAuthenticationFilter拦截路径属性DEFAULT_FILTER_PROCESSES_URL = "/auth";
     * SpringSocialConfigurer 配置 SocialAuthenticationFilter过滤器代码
     * 	http.authenticationProvider(new SocialAuthenticationProvider(usersConnectionRepository,
     * 	socialUsersDetailsService)).addFilterBefore(postProcess(filter), AbstractPreAuthenticatedProcessingFilter.class);
     * 	postProcess(filter)配置过滤器
     *  重写postProcess(filter)方法来配置拦截路径
     * @param object
     * @param <T>
     * @return
     */
    @Override
    protected <T> T postProcess(T object) {

        SocialAuthenticationFilter socialAuthenticationFilter =
                (SocialAuthenticationFilter) super.postProcess(object);
        socialAuthenticationFilter.setFilterProcessesUrl(filterProcessesUrl);
        socialAuthenticationFilter.setSignupUrl(signupUrl);
        return (T)socialAuthenticationFilter;
    }
}
